package sjtu.ist.warehouse4ws.service;


import java.util.List;

import sjtu.ist.warehouse4ws.dao.RolepermissionsDao;
import sjtu.ist.warehouse4ws.dao.cust.CustRolepermissionsDao;
import sjtu.ist.warehouse4ws.model.CustRolepermissions;
import sjtu.ist.warehouse4ws.model.Rolepermissions;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;

public class RolepermissionsServiceImpl implements RolepermissionsService {
    private RolepermissionsDao rolepermissionsDao;
    private CustRolepermissionsDao custRolepermissionsDao;
    
	public void setRolepermissionsDao(
			RolepermissionsDao rolepermissionsDao) {
		this.rolepermissionsDao = rolepermissionsDao;
	}


	public void setCustRolepermissionsDao(
			CustRolepermissionsDao custRolepermissionsDao) {
		this.custRolepermissionsDao = custRolepermissionsDao;
	}


	@Override
	public Integer addRolepermissions(Rolepermissions rolepermissions,int companyId) {
		// TODO Auto-generated method stub
		if(companyId==Constants.ADMIN_COMPANY_ID){
			return rolepermissionsDao.save(rolepermissions);
		}else{
			CustRolepermissions cr=new CustRolepermissions();
			PropertyHelper.copyProperties(rolepermissions, cr);
			return custRolepermissionsDao.save(cr);			
		}
	}


	@Override
	public List getRolepermissionsById(String id) {
		// TODO Auto-generated method stub
		return (List<Rolepermissions>)rolepermissionsDao.findById(id);
	}
	
	@Override
	public List<String> getPermissionsByRoleid(String id) {
		// TODO Auto-generated method stub
		List<String> list=(List<String>)rolepermissionsDao.findPermissionsByRoleid(id);
		for(int i=0;i<list.size();i++)
		{
			System.out.println(list.get(i));
		}
		return (List<String>)rolepermissionsDao.findPermissionsByRoleid(id);
		
	}

}
